import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Fixed } from './fixed.interface';
import { Model } from 'mongoose';
import { CreateFixedDTO, EditFixedDTO } from './fixed.dto';

@Injectable()
export class FixedService {
    constructor(@InjectModel('fixed') private readonly fixedModel: Model<Fixed>)  {}

    async findAll(): Promise<Fixed[]> {
        return await this.fixedModel.find();
    }

    async findWhere(filter?: object): Promise<Fixed[]> {
        return await this.fixedModel.find(filter);
    }

    async find(id: string): Promise<Fixed> {
        return await this.fixedModel.findById(id);
    }
    
    async addone(body: CreateFixedDTO): Promise<Fixed> {
        return await this.fixedModel.create(body);
    }

    async editone(id: string, body: EditFixedDTO): Promise<Fixed> {
        return await this.fixedModel.findByIdAndUpdate(id, body);
    }
    
    async delete(id: string): Promise<Fixed> {
        return await this.fixedModel.findByIdAndDelete(id);
    }
}
